package com.hongyue.dey03;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Demo {
    public static void main(String[] args) {
        HashMap<String, Student> hm = new HashMap<>();
        hm.put("heima001", new Student("小明", 18));
        hm.put("heima002", new Student("小红", 16));
        hm.put("heima003", new Student("小路", 19));
        hm.put("heima004", new Student("小胖", 20));
        Set<String> keySet = hm.keySet();
        for (String key : keySet) {
            Student student = hm.get(key);
            String name = student.getName();
            int age = student.getAge();
            System.out.println("学号" + key + "\t 姓名" + name + "\t 年龄" + age);
        }
        System.out.println("----------------------------");
        Set<Map.Entry<String, Student>> entries = hm.entrySet();
        for (Map.Entry<String, Student> entry : entries) {
            String key = entry.getKey();
            Student value = entry.getValue();
            String name = value.getName();
            int age = value.getAge();
            System.out.println("学号" + key + "\t 姓名" + name + "\t 年龄" + age);
        }
    }
}
